package org.example;

import cn.hutool.json.JSONUtil;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import static org.apache.rocketmq.spring.annotation.ConsumeMode.ORDERLY;

@Component
@RocketMQMessageListener(topic = "bootOrderlyTopic",
        consumerGroup = "boot-order-consumerGroup",
        consumeMode =  ConsumeMode.ORDERLY //   这个一定要配置， 否则顺序会乱

)
public class OrderMessageListener implements RocketMQListener<MessageExt> {


    @Override
    public void onMessage(MessageExt messageExt) {


        String msgStr = new String(messageExt.getBody());
//        System.out.println("message is " + msgStr);


        MsgModel msgModel = JSONUtil.toBean(msgStr, MsgModel.class);


        System.out.println("MsgModel is : " + msgModel);
//        System.out.println("msg_id  is :" + messageExt.getMsgId());
    }
}
